var comeco : colisor_comeco;
var caixa : Transform;
var tonto : boolean;
var timer : float;
var flecha : Transform;
var vida : int = 2;
var arco : arco;
var player : Transform;
var pulo : boolean;
var pedra : Transform;
var porta : igor_fisica;
var cair_chao : boolean;
var particula : GameObject;
var particula2 : GameObject;
var particula3 : GameObject;
function Update () 
{
	pedra.transform.position.x = transform.position.x;
	
	if(vida == 0)
	{
		Destroy (gameObject);
		porta.chave = true;
	}
	
	if(comeco.bulea == true)
	{
		MovimentoBoss();
	}
	
	if(tonto == true)
	{
		timer += Time.deltaTime;
	}
	if(timer >= 7)
	{
		tonto = false;
		timer = 0;
	}	
	
	if(transform.position.x > 3.539237 && player.transform.position.y < -2.7)
	{
		Morre();
	}
	if(cair_chao)
	{
	    particula2.active = true;
		pedra.transform.position.y -= 0.05;
		pedra.transform.position.x = pedra.transform.position.x;
	}
}
function Morre ()
{
particula3.active = true;
yield WaitForSeconds (1);		
Destroy(player.gameObject);
Application.LoadLevel(Application.loadedLevel);
}
function OnCollisionEnter (arroz : Collision)
{
	if(arroz.gameObject.name == "caixa")
	{
		tonto = true;
		caixa.transform.position.y = 5.703748;
	}
	if(arroz.gameObject.name == "flecha" && tonto == true)
	{
		vida --;
		flecha.transform.position.x = -5.483951;
		arco.flechar = false;
		tonto = false;
		timer = 0;
	}
	if(arroz.gameObject.name == "flecha" && tonto == false)
	{
		flecha.transform.position.x = -5.483951;
		arco.flechar = false;
	}
	if(arroz.gameObject.tag == "Chao")
	{
		pulo = true;
		
	}
	
}
function OnTriggerEnter (other : Collider)
{
	if((other.gameObject.name == "colisor_posicao") && (tonto == false) && (pulo == true))
	{
		rigidbody.AddForce(Vector3(0,1000,0));
		pulo = false;
		cair_chao = true;	
	}
}

function MovimentoBoss ()
{
if(player.transform.position.y < transform.position.y)
	{
		if(tonto == false)
		{
			if(transform.position.x > player.transform.position.x)
			{
				if(transform.position.x > -1.127398)
					{
						transform.Translate(-0.03,0,0);
					}
					else
					{
						if(player.transform.position.x < -2.172821)
						{
							particula.active = true;
							yield WaitForSeconds(1); 
							Destroy(player.gameObject);
							Application.LoadLevel(Application.loadedLevel);
						}
					}
			}
			
			if(transform.position.x < player.transform.position.x)
				transform.Translate(0.02,0,0);
			
			
		}
		
	}
}
